package com.ybc.reactor;


import reactor.core.publisher.Mono;

public class MonoDemo {
    public static void main(String[] args) throws InterruptedException {
      test();
    }

    static void test1(){
        // 创建一个 Mono，用于异步返回一个字符串
        Mono<String> mono = Mono.just("Hello, Reactive Programming!");
        System.out.println(mono.getClass());

        // 当 Mono 完成时，输出结果
        mono.subscribe(result -> {
            System.out.println("结果: " + result);
        });

    }


    static void test() throws InterruptedException {
        Mono<String> asyncRequest = Mono.fromCallable(() -> {
            // 模拟异步操作
            System.out.println("异步操作开始...");
            Thread.sleep(2000);  // 模拟延时
            return "Hello, World!";
        });
        System.out.println("test");
        Thread.sleep(1000);  // 模拟延时


        asyncRequest.subscribe(result -> {
            System.out.println("结果: " + result);
        });
        System.out.println("主线程继续执行...");

    }
}
